package com.example.task1.ui.AllService.traffic;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.TrafficBannerBean;
import com.example.task1.bean.TrafficHomeListBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class TrafficHomeListAdapter extends BaseAdapter<TrafficHomeListBean.RowsDTO> {

    private Context context;

    private List<TrafficHomeListBean.RowsDTO> mData = new ArrayList<>();
    private TextView tvTitle;
    private TextView tvPhone;
    private TextView tvTime;
    private TextView tvAddress;

    public TrafficHomeListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<TrafficHomeListBean.RowsDTO> rows) {
        int size = mData.size();
        mData.addAll(rows);
        notifyItemInserted(size);
    }

    @Override
    protected int getLayout() {
        return R.layout.traffichomelist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<TrafficHomeListBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, TrafficHomeListBean.RowsDTO date) {
        tvAddress.setText("地址：" + date.getAddress());
        tvPhone.setText("联系方式：" + date.getPhone());
        tvTime.setText(date.getRemarks());
        tvTitle.setText(date.getPlaceName());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, TrafficDetailsActivity.class, date.getId());
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View itemView) {
        tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        tvPhone = (TextView) itemView.findViewById(R.id.tv_phone);
        tvTime = (TextView) itemView.findViewById(R.id.tv_time);
        tvAddress = (TextView) itemView.findViewById(R.id.tv_address);
    }
}
